package com.idlecode.service;

import com.idlecode.bean.DataSourceEntity;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: IdleCode
 * @description
 * @author: rongjuwei
 * @create: 2024-02-06 09:37
 **/
@Service
@State(name = "IdleCodeDataSources", storages = @Storage(value = "IdleCodeDataSources.xml", roamingType = RoamingType.DISABLED))
public final class DataSourceService implements PersistentStateComponent<DataSourceService> {

    private List<DataSourceEntity> dataSources = new ArrayList<>();

    public static DataSourceService getInstance() {
        return ApplicationManager.getApplication().getService(DataSourceService.class);
    }

    @Override
    public DataSourceService getState() {
        return this;
    }

    @Override
    public void loadState(DataSourceService state) {
        if (null == state) {
            return;
        }
        this.dataSources = state.dataSources;
    }

    public List<DataSourceEntity> getDataSources() {
        return dataSources;
    }

    public void setDataSources(List<DataSourceEntity> dataSources) {
        this.dataSources = dataSources;
    }
}
